// RebootNet.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	std::cout << "argc = " << argc << std::endl;
	LPCTSTR str = (LPCTSTR)argv[1];
	CStringA ss = str;
	//str.Format("%s",argv);
	LPSTR cmdline = ss.GetBuffer();

	STARTUPINFOA si = {0};
	si.cb = sizeof(si);

	PROCESS_INFORMATION pi = {0};

	SECURITY_ATTRIBUTES saProcess, saThread ;
	saProcess.nLength = sizeof(saProcess) ;
	saProcess.lpSecurityDescriptor = NULL ;
	saProcess.bInheritHandle = TRUE ;

	saThread.nLength = sizeof(saThread) ;
	saThread.lpSecurityDescriptor = NULL ;
	saThread.bInheritHandle = FALSE ;

	BOOL bLaunchedSetup = ::CreateProcessA(NULL, 
		cmdline,
		&saProcess,
		&saThread, 
		FALSE, 
		DETACHED_PROCESS, 
		NULL, 
		NULL, 
		&si,
		&pi);

	DWORD exitCode = 0;

	std::cout << "argv = " << argv[1] << std::endl;
	std::cout << "cmdline = " << cmdline << std::endl;
	std::cout << "bLaunchedSetup = " << bLaunchedSetup << std::endl;
	
	if (bLaunchedSetup != 0)
	{
		DWORD ret = WaitForSingleObject( pi.hProcess, INFINITE ) ;	

		::GetExitCodeProcess(pi.hProcess, &exitCode);

		::CloseHandle(pi.hThread);
		::CloseHandle(pi.hProcess);
	}

	return 0;
}

